package cn.strive.eams.application.controller;

import cn.strive.eams.application.pojo.dto.ApplicationQuery;
import cn.strive.eams.application.pojo.vo.ApplicationVO;
import cn.strive.eams.application.service.ApplicationService;
import cn.strive.eams.base.response.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/application")
@Api(tags = "申请管理")
@Slf4j
public class ApplicationController {

    @Autowired
    ApplicationService applicationService;

    @GetMapping("/select")
    @ApiOperation(value = "查询申请列表")
    public JsonResult select(ApplicationQuery applicationQuery) {
        log.info("查询申请列表:applicationQuery={}", applicationQuery);
        List<ApplicationVO> list = applicationService.selectAll(applicationQuery);
        return JsonResult.ok(list);
    }

    @GetMapping("/find/{id}")
    @ApiOperation(value = "查询申请详情")
    public JsonResult selectById(@PathVariable Long id) {
        log.info("查询申请详情:id={}", id);
        List<ApplicationVO> list = applicationService.selectById(id);
        return JsonResult.ok(list);
    }

    @PutMapping("/cancel/{id}")
    @ApiOperation(value = "取消申请")
    public JsonResult cancel(@PathVariable Long id) {
        log.info("取消申请:id={}", id);
        applicationService.cancel(id);
        return JsonResult.ok();
    }

    @GetMapping("/select/busrequire/{id}")
    @ApiOperation(value = "查询申请详情")
    public JsonResult select(@PathVariable Long id) {
        log.info("查询申请详情:id={}", id);
        List<ApplicationVO> list = applicationService.selectById(id);
        return JsonResult.ok(list);
    }
}
